home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!usenet
- From: clamage@Eng.sun.com (Steve Clamage)
- Newsgroups: comp.std.c++
- Subject: Re: Quick questions
- Date: 26 Mar 1996 00:30:02 GMT
- Organization: Sun Microsystems Inc.
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4j7a64$l9i@engnews1.Eng.Sun.COM>
- References: <4j5b26$1e7a@mule1.mindspring.com>
- Reply-To: clamage@Eng.sun.com
- NNTP-Posting-Host: taumet.eng.sun.com
- X-Nntp-Posting-Host: taumet.eng.sun.com
- Content-Length: 1900
- X-Lines: 40
-
- In article 1e7a@mule1.mindspring.com, abell@mindspring.com (Andrew Bell) writes:
-
- >2) From a previous post on this group, it looks like the standard will
- >allow one to define conversion operators for pre-existing, source code
- >untouchable data types. Yes? No? What will this look like? I have the
- >May copy of the WP, and don't see any mention of this.
-
- I'm not sure I understand what you are asking. If you mean can you define
- a conversion operator from a user-defined class to a predefined type
- like int or double, then yes, that has long been part of C++.
- class myclass {
- public:
- operator int() { ... }
- };
-
- >3) I often write what I call "pure wrapper" classes to give access
- >protection and data abstraction to pre-existing data types. A pure
- >wrapper class is a class that adds no member variables or virtual
- >member functions to a class/struct that has no virtual functions of
- >its own, so their size and alignment should be the same and casting
- >between the two should be perfectly safe. The new standard doesn't
- >have any special support (for example, allowing it automatically) for
- >this, does it?
-
- I assume you mean a class like
- class Short { short val; };
- with non-virtual member functions added. You can't assume the size and
- alignment of the class will be the same as its only data member, and no,
- the standard provides no special support for this special case.
-
- Example: It is common for shorts to be aligned on 2-byte boundaries,
- but all structured types to require alignment on 4-byte boundaries.
- In this case, all struct types would have a size which is a
- multiple of 4. Casting between short* and Short*, or between
- short& and Short&, could cause problems.
-
- >4) With RTTI, a derived class that doesn't change any virtual member
- >funcs or add any properties to a base class still evaluates to a
- >different object type, correct?
-
- Yes. The typeids of two types compare equal if and only if they are
- the same type. Base and derived classes are not ever the same type.
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
-
-
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-